﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using UniversalDataAccess;
using UniversalDataAccess.BusinessEntities;
using System.Configuration;

namespace WebApplication1
{
    /// <summary>
    /// Summary description for ManagingDivisionLogicService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class ManagingDivisionLogicService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        #region Select / Insert / Update /Delete ManagingDivision.

        [WebMethod]
        public ManagingDivision SelectManagingDivision_By_DataBase_And_Id(string databaseName, int id)
        {
            try
            {
                ManagingDivisionsDataAccess dataAccess = null;

                dataAccess = new ManagingDivisionsDataAccess(databaseName, ConfigurationManager.ConnectionStrings[databaseName].ConnectionString, false);
                return dataAccess.SelectManagingDivisionBy_Id(id);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        [WebMethod]
        public List<ManagingDivision> SelectManagingDivisionListByDataBaseName(string dataBaseName)
        {
            try
            {
                ManagingDivisionsDataAccess e = new ManagingDivisionsDataAccess(dataBaseName, ConfigurationManager.ConnectionStrings[dataBaseName].ConnectionString, false);

                return e.SelectManagingDivisionsList();
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        [WebMethod]
        public void InsertManagingDivision(ManagingDivision division)
        {
            try
            {
                ManagingDivisionsDataAccess e = new ManagingDivisionsDataAccess(division.DataBaseName,
                    ConfigurationManager.ConnectionStrings[division.DataBaseName].ConnectionString, false);

                int new_Id = -1;
                e.InsertManagingDivision(division, ref new_Id);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        [WebMethod]
        public void UpdateManagingDivision(ManagingDivision division)
        {
            try
            {
                ManagingDivisionsDataAccess e = new ManagingDivisionsDataAccess(division.DataBaseName,
                    ConfigurationManager.ConnectionStrings[division.DataBaseName].ConnectionString, false);

                e.UpdateManagingDivision(division);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        [WebMethod]
        public void DeleteManagingDivision(ManagingDivision division)
        {
            try
            {
                ManagingDivisionsDataAccess e = new ManagingDivisionsDataAccess(division.DataBaseName,
                    ConfigurationManager.ConnectionStrings[division.DataBaseName].ConnectionString, false);

                e.DeleteManagingDivision(division);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        #endregion        
    }
}
